package org.example.mybatis.controller;

import org.example.mybatis.domain.User;
import org.example.mybatis.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HelloController {

    private final UserService userService;
    public HelloController(UserService userService) {
        this.userService = userService;
    }
//当访问users调用getAllUsers()
    @GetMapping("/users")
    public List<User> getUsers() {
        return userService.getAllUsers();
    }
}

//1.控制层：程序入口，处理前端的http请求；调取service层获取业务数据